package heven.holt.library.di

import android.app.Application
import androidx.room.Room
import dagger.Module
import dagger.Provides
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import heven.holt.library.database.AppDatabase
import heven.holt.library.database.dao.DownloadDao
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
    @Provides
    @Singleton
    fun provideAppDatabase(application: Application): AppDatabase {
        return Room.databaseBuilder(application, AppDatabase::class.java, "wan-android").build()
    }

    @Provides
    @Singleton
    fun provideDownloadDao(db: AppDatabase): DownloadDao {
        return db.downloadDao()
    }
}

@EntryPoint
@InstallIn(SingletonComponent::class)
interface DownloadDaoProviderEntryPoint {
    fun provideDownloadDao(): DownloadDao
}